package com.yyh.javase1;

import java.math.BigDecimal;
import java.util.Random;

public class Demo1 {
    public static void main(String[] args) {
        //生成一个随机100内的小数
        Random random = new Random();
        double num = random.nextDouble() * 100;
        System.out.println("随机数为：");
        System.out.println(num);
        System.out.println("转换为：");
        //转换为保留两位小数的字符串
        BigDecimal bd = new BigDecimal(num);
        System.out.println(bd.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
    }
}
